//
//  NSObject+YYHelper.m
//  YYNavigation
//
//  Created by yown on 2025/7/11.
//

#import "NSObject+YYHelper.h"
#import "YYNavigationMacro.h"

@implementation NSObject (YYHelper)

+ (UIWindow *)yy_mainWindow {
    if (@available(iOS 13.0, *)) {
        // iOS 13及以上从Scene中获取
        UIWindowScene *windowScene = (UIWindowScene *)[UIApplication sharedApplication].connectedScenes.anyObject;
        UIWindow *window = nil;
        if (windowScene) {
            window =  windowScene.windows.firstObject;
        }
        
        if (!window) {
            window = [UIWindow new];
        }
        return window;
    } else {
        // iOS 13以下从windows数组获取
        return [UIApplication sharedApplication].windows.firstObject;
    }
}

+ (UIInterfaceOrientation)deviceOrientation {
    if (@available(iOS 13.0, *)) {
        // iOS 13及以上从Scene中获取
        UIWindowScene *windowScene = (UIWindowScene *)[UIApplication sharedApplication].connectedScenes.anyObject;
        return windowScene.interfaceOrientation;
    } else {
        // iOS 13以下从windows数组获取
        return [UIApplication sharedApplication].statusBarOrientation;
    }
}

+ (CGFloat)yy_statusBarHeight {
    CGPoint point = [self yy_mainWindow].safeAreaLayoutGuide.layoutFrame.origin;
    return MAX(point.x, point.y);
}

+ (CGFloat)yy_naviBarWidth {
    return MIN(YYScreenWidth, YYScreenHeight);
}

+ (CGFloat)yy_naviBarHeight {
    return [self yy_statusBarHeight] + 44;
}

@end
